package com.example.controller;

import com.example.model.auto.RoleInfo;
import com.example.service.IRoleInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限信息表 前端控制器
 * </p>
 *
 * @author 达瓦里氏
 * @since 2021-11-15
 */
@RestController
@RequestMapping("/role")
@CrossOrigin
public class RoleInfoController {

    @Autowired(required = false)
    private IRoleInfoService iRoleInfoService;

    /*查询所有角色*/
    @GetMapping("/getRole")
    public List<RoleInfo> getRole(){
        return iRoleInfoService.list();
    }

    /*通过id查询角色*/
    @GetMapping("/getRoleById/{id}")
    public RoleInfo getRoleById(@PathVariable("id") int id){
        return iRoleInfoService.getById(id);
    }

    /*修改角色*/
    @PostMapping("/updateRole")
    public void updateRole(@RequestBody RoleInfo roleInfo){
        iRoleInfoService.updateById(roleInfo);
    }

    /*添加角色*/
    @PostMapping("/setRole")
    public void setRole(@RequestBody RoleInfo roleInfo){
        iRoleInfoService.save(roleInfo);
    }


    /*删除角色*/
    @PostMapping("/deletedById/{id}")
    public boolean deleted(@PathVariable("id") int id){
        return iRoleInfoService.removeById(id);
    }


}
